Typical HAL GENERIC use cases for migration ¶
This section provides information about the applicable HAL GENERIC architecture use cases.
Important
The most significant change for the HAL GENERIC driver is its split into four distinct dedicated drivers:
GENERIC
SYSCFG/SBS
DBGMCU
VREFBUF
This restructuring enhances modularity and clarity, allowing for more focused and maintainable code management.
Use case: User application in most basic use case ¶
This use case shows a minimal HAL initialization flow and tick/time-base usage.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
int main(void)
{
HAL_Init();
/*
...
*/
/* Update Tick frequency */
if (HAL_SetTickFreq(HAL_TICK_FREQ_10KHZ) != HAL_OK)
{
return HAL_ERROR;
}
/* Update Tick interrupt priority */
if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
{
return HAL_ERROR;
}
/* Get Tick */
uint32_t tick1 = HAL_GetTick();
/* Delay */
HAL_Delay(1000);
/* Get Tick */
uint32_t tick2 = HAL_GetTick();
/* Suspend Tick */
HAL_SuspendTick();
/* Resume Tick */
HAL_ResumeTick();
return HAL_OK;
}
|
int main(void)
{
HAL_Init();
/*
...
*/
/* Update Tick frequency and interrupt priority */
if (HAL_InitTick(HAL_TICK_FREQ_10KHZ, TICK_INT_PRIORITY) != HAL_OK)
{
return HAL_ERROR;
}
/* Get Tick */
uint32_t tick1 = HAL_GetTick();
/* Delay */
HAL_Delay(1000);
/* Get Tick */
uint32_t tick2 = HAL_GetTick();
/* Suspend Tick */
HAL_SuspendTick();
/* Resume Tick */
HAL_ResumeTick();
return HAL_OK;
}
|
Key changes ¶
HAL2 merges tick frequency and tick interrupt priority configuration into
HAL_InitTick(hal_tick_freq_t tick_freq, uint32_t tick_priority).HAL1 uses separate calls (for example
HAL_SetTickFreq()andHAL_InitTick(uint32_t TickPriority)) for tick configuration.
Use case: Retrieve device information ¶
This use case shows how to retrieve device identifiers (revision/device IDs, unique ID) and the HAL version.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
int main(void)
{
HAL_Init();
/*
...
*/
uint32_t tmp0;
uint32_t tmp1;
uint32_t tmp2;
tmp0 = HAL_GetUIDw0();
tmp1 = HAL_GetUIDw1();
tmp2 = HAL_GetUIDw2();
printf("Device unique ID: %d-%d-%d", tmp0, tmp1, tmp2);
uint32_t version = HAL_GetHalVersion();
printf("HAL Version: %d", version);
}
|
int main(void)
{
HAL_Init();
/*
...
*/
hal_device_uid_t device_uid;
HAL_GetDeviceUniqueID(&device_uid);
printf("Device unique ID: %d-%d-%d", device_uid.uid_0, device_uid.uid_1, device_uid.uid_2);
uint32_t version = HAL_GetVersion();
printf("HAL Version: %d", version);
}
|
Key changes ¶
In HAL2, revision and device ID access is provided by the dedicated DBGMCU driver (for example
HAL_DBGMCU_GetRevisionID()andHAL_DBGMCU_GetDeviceID()).In HAL2, the unique device ID getters are consolidated into
HAL_GetDeviceUniqueID(hal_device_uid_t *p_uid).In HAL2,
HAL_GetVersion()replacesHAL_GetHalVersion().
Use case: VREFBUF configuration ¶
This use case shows how VREFBUF configuration is handled after the HAL GENERIC driver split.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
int main(void)
{
HAL_Init();
/*
...
*/
/* Set Voltage Scaling */
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE0);
/* Configure the high impedance mode */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE);
/* Enable VREFBUF */
HAL_SYSCFG_EnableVREFBUF();
}
|
int main(void)
{
HAL_Init();
/*
...
*/
hal_vrefbuf_config_t p_config;
p_config.mode = HAL_VREFBUF_MODE_EXT_VOLTAGE_REF;
p_config.voltage_scale = HAL_VREFBUF_VOLTAGE_SCALE0;
/* Configure and enable VREFBUF (Voltage scale and VREFBUF mode) */
HAL_VREFBUF_SetConfig(VREFBUF1, &p_config);
}
|
Key changes ¶
The HAL GENERIC driver split introduces a dedicated VREFBUF driver for configuration.
In HAL2, VREFBUF configuration and enable are consolidated into
HAL_VREFBUF_SetConfig().





